/**
 *
 */
package anysware.source.resource;

import java.util.Collection;

import org.restlet.data.Status;
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;

import anysware.core.rest.resource.AnyswareResource;
import anysware.source.Source;
import anysware.source.SourceService;

/**
 * SourcesResource can list all available {@link Source}.
 *
 * @author keke<keke@codehaus.org>
 * @revision $Revision: 111 $
 * @version 0.0.1
 */
public class SourcesResource extends AnyswareResource {
	private SourceService	sourceService;

	/*
	 * (non-Javadoc)
	 *
	 * @see org.restlet.resource.Resource#represent(org.restlet.resource.Variant)
	 */
	@Override
	public Representation represent(final Variant variant)
	        throws ResourceException {
		final Collection<Source> sourceList = sourceService.getAllSources();
		final Representation rep = repHelper.toRepresentation("sources",
		        sourceList, variant);
		if (rep == null) {
			getResponse().setStatus(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
		}
		return rep;
	}

	/**
	 * @param sourceService
	 *            the sourceService to set
	 */
	public void setSourceService(final SourceService sourceService) {
		this.sourceService = sourceService;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.restlet.resource.Resource#init(org.restlet.Context,
	 *      org.restlet.data.Request, org.restlet.data.Response)
	 */
	@Override
	protected void initInner() {
		setModifiable(false);
		setReadable(true);
		setAvailable(true);
	}

}
